package com.hg.design.behavior.visitor.biancheng.ex3;

import java.util.ArrayList;
import java.util.List;

public class CompositeElement implements Element {
    private List<Element> list = new ArrayList<>();

    @Override
    public void accept(Visitor visitor) {
        visitor.visit(this);
    }

    public String operation() {
        String tmp = "容器元素操作：";
        for (Element element : this.list) {
            tmp += element.operation() + "，";
        }
        return tmp.substring(0, tmp.length()-2) + "。";
    }

    public void add(Element element) {
        this.list.add(element);
    }

    public void remove(Element element) {
        this.list.remove(element);
    }

    public Element getChild(int i) {
        return this.list.get(i);
    }
}
